-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
[BugFix][V0] Fix AssertionError for prompt_logprobs #19844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @xu-song, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a critical AssertionError
that occurred during log probability calculation within the sampler.py
module. The fix involves a precise adjustment to an indexing calculation, resolving an off-by-one issue that was likely causing mismatches in token list lengths, thereby preventing the assertion failure.
Highlights
- Bug Fix: Indexing Correction: Corrected an off-by-one error in the calculation of
next_token_index_end
within the_get_next_prompt_tokens
function invllm/model_executor/layers/sampler.py
. This change removes an extraneous+1
from the end index calculation on line 1200. - Assertion Error Resolution: This fix directly addresses and resolves the
AssertionError
(Fixes #13105) that occurred whenlen(next_token_ids)
did not matchlen(query_indices)
during log probability calculation, by ensuring correct token indexing.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request fixes an AssertionError
in the V0 sampler's prompt log probability calculation. The change correctly adjusts the slicing logic for next_prompt_tokens
to ensure its length matches the number of query_indices
, resolving an off-by-one error. The reasoning behind the fix seems sound based on how prompt logprobs are handled.
To further improve the robustness of this area, consider adding a specific unit test that reproduces the failing scenario (e.g., a prompt of a certain length processed with prompt_logprobs
enabled, potentially with chunked prefill if that was a factor) to ensure this bug does not regress in the future. The PR description checklist also indicates that the test plan and results are not yet provided, which would be valuable for verifying the fix.
next_token_index_end = min(computed_len + query_len, | ||
len(prompt_tokens)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly adjusts the next_token_index_end
to fix an off-by-one error when calculating the next_prompt_tokens
for prompt log probabilities in the V0 sampler. Here's a breakdown of why this is the correct fix:
- Context: This function
_get_next_prompt_tokens
is called by_get_prompt_logprobs
(in the V0 sampler) to get the target tokens for which log probabilities are being computed. query_len
Argument: Thequery_len
argument passed to this function from_get_prompt_logprobs
corresponds toseq_group.query_len
. This represents the total number of tokens in the current part of the prompt being processed (e.g., the full prompt length or a chunk in chunked prefill).query_indices
Length: Thequery_indices
(which areseq_group.prompt_logprob_indices
in_get_prompt_logprobs
) represent the specific positions in the logits tensor for which prompt logprobs are needed. If the current prompt part hasN
tokens (P_0, P_1, ..., P_{N-1}
), logprobs are typically computed for predictingP_1
(from contextP_0
),P_2
(from contextP_0,P_1
), and so on, up toP_{N-1}
. Thus, there areN-1
such logprobs, andlen(query_indices)
isN-1
(this corresponds toprompt_logprob_len = seq_group.query_len - 1
, assumingdo_sample=True
andnum_prefill_sample=1
in_prepare_seq_groups
).next_token_ids
Length: Thenext_token_ids
(which arenext_prompt_tokens
returned by this function) must matchlen(query_indices)
. These are the target tokensP_1, ..., P_{N-1}
.- Original Bug:
next_token_index_start = computed_len + 1
.- Original
next_token_index_end
was effectivelycomputed_len + query_len + 1
(beforemin
). - This resulted in
len(next_prompt_tokens) = (computed_len + query_len + 1) - (computed_len + 1) = query_len
(which isN
in the example above). - The assertion
len(next_token_ids) == len(query_indices)
becameN == N-1
, which failed, causing theAssertionError
.
- Fix:
- New
next_token_index_end
is effectivelycomputed_len + query_len
(beforemin
). - This results in
len(next_prompt_tokens) = (computed_len + query_len) - (computed_len + 1) = query_len - 1
(which isN-1
in the example above). - The assertion now becomes
N-1 == N-1
, which passes.
- New
This change ensures that the number of target tokens extracted matches the number of logit entries for which prompt logprobs are being calculated, resolving the AssertionError
.
55f5364
to
d34c43b
Compare
@xu-song what version of vLLM are you using in the provided example? This change only applies to V0, so I don't think it should apply to your example unless you are explicitly disabling V1 via the env var. |
latest V0 |
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
Fix #13105
Reproduce of
prompt_logprobs